using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Domain.Ranges
{
    [TestClass]
    public class WhenDeterminingIfDateRangeIsCovered
    {
        [TestMethod]
        public void ShouldReturnTrueWhenPeriodIsCompletelyCovered()
        {
            DateRange periodToCover = new DateRange(new DateTime(2008, 1, 1), new DateTime(2008, 12, 31));

            IEnumerable<DateRange> coveredPeriods = new DateRange[]
                {
                new DateRange(new DateTime(2000, 1, 1), new DateTime(2008, 6, 1)),
                new DateRange(new DateTime(2008, 6, 2), new DateTime(2008, 6, 30)),
                new DateRange(new DateTime(2008, 1, 1), new DateTime(2009, 1, 1))
                };

            Assert.IsTrue(periodToCover.IsCoveredByRanges(coveredPeriods));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenPeriodIsNotCompletelyCovered()
        {
            DateRange periodToCover = new DateRange(new DateTime(2008, 1, 1), new DateTime(2008, 12, 31));

            IEnumerable<DateRange> coveredPeriods = new DateRange[]
                {
                new DateRange(new DateTime(2000, 1, 1), new DateTime(2008, 6, 1)),
                new DateRange(new DateTime(2008, 6, 2), new DateTime(2008, 6, 30)),
                new DateRange(new DateTime(2010, 1, 1), new DateTime(2010, 12, 31))
                };

            Assert.IsFalse(periodToCover.IsCoveredByRanges(coveredPeriods));
        }

        [TestMethod]
        public void ShouldReturnTrueWhenPeriodTillEndOfTimeIsCompletelyCovered()
        {
            DateRange periodToCover = new DateRange(new DateTime(2008, 1, 1), new DateTime(9999, 12, 31));

            IEnumerable<DateRange> coveredPeriods = new DateRange[]
                {
                new DateRange(new DateTime(2000, 1, 1), new DateTime(2008, 6, 1)),
                new DateRange(new DateTime(2008, 6, 2), new DateTime(2008, 6, 30)),
                new DateRange(new DateTime(2008, 1, 1), new DateTime(2009, 1, 1)),
                new DateRange(new DateTime(2009, 1, 2), new DateTime(9999, 12, 31))
                };

            Assert.IsTrue(periodToCover.IsCoveredByRanges(coveredPeriods));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenPeriodTillEndOfTimeIsNotCompletelyCovered()
        {
            DateRange periodToCover = new DateRange(new DateTime(2008, 1, 1), new DateTime(9999, 12, 31));

            IEnumerable<DateRange> coveredPeriods = new DateRange[]
                {
                new DateRange(new DateTime(2000, 1, 1), new DateTime(2008, 6, 1)),
                new DateRange(new DateTime(2008, 6, 2), new DateTime(2008, 6, 30)),
                new DateRange(new DateTime(2008, 1, 1), new DateTime(2009, 1, 1)),
                new DateRange(new DateTime(2009, 1, 2), new DateTime(9999, 12, 30))
                };

            Assert.IsFalse(periodToCover.IsCoveredByRanges(coveredPeriods));
        }

        [TestMethod]
        public void ShouldReturnTrueWhenEachDayIsCovered()
        {
            DateRange periodToCover = new DateRange(new DateTime(2008, 1, 1), new DateTime(9999, 12, 31));

            IEnumerable<DateRange> coveredPeriods = new DateRange[]
                {
                new DateRange(new DateTime(2000, 1, 1), new DateTime(2008, 6, 1)),
                new DateRange(new DateTime(2008, 6, 2), new DateTime(2008, 6, 30)),
                new DateRange(new DateTime(2008, 1, 1), new DateTime(9999, 12, 30)),
                new DateRange(new DateTime(9999, 12, 31), new DateTime(9999, 12, 31))
                };

            Assert.IsTrue(periodToCover.IsCoveredByRanges(coveredPeriods));
        }

        [TestMethod]
        public void ShouldReturnTrueWhenEachDayOfPeriodIsCovered()
        {
            DateRange periodToCover = new DateRange(new DateTime(2008, 1, 1), new DateTime(9999, 12, 31));

            IEnumerable<IDiscreteValuesRange<DateTime>> coveredPeriods = new DateRange[]
                {
                new DateRange(new DateTime(2000, 1, 1), new DateTime(2008, 6, 1)),
                new DateRange(new DateTime(2008, 6, 2), new DateTime(2008, 6, 30)),
                new DateRange(new DateTime(2008, 1, 1), new DateTime(9999, 12, 29)),
                new DateRange(new DateTime(9999, 12, 30), new DateTime(9999, 12, 30)),
                new DateRange(new DateTime(9999, 12, 31), new DateTime(9999, 12, 31))
                };

            Assert.IsTrue(periodToCover.IsCoveredBy(coveredPeriods));
        }
    }
}